#ifndef __EDO_MODULATOR_MANAGER_H__
#define __EDO_MODULATOR_MANAGER_H__

#include "Includes.h"
#include "EdoModulator.h"

#define		strAttr(x)		modulator->getStringAttribute(T(x))
#define		intAttr(x,y)		modulator->getIntAttribute(x,y)
#define		boolAttr(x,y)		modulator->getBoolAttribute(x,y)

#define		EDO_CTRLR			T("edoCtrlr")
#define		EDO_CTRLR_FORMULA	T("edoCtrlrFormula")
#define		EDO_CTRLR_IDX		T("edoCtrlrIndex")

class EdoModulatorManager
{
	public:
		enum MidiMessageType
		{
			None,
			MidiCC,
			MidiNoteOn,
			MidiNoteOff,
			MidiRPN,
			MidiNRPN,
			MidiSysEx,
			MidiProgramChange,
			MidiBankChange,
			MidiActiveSense,
			MidiAfterTouch,
			MidiChannelPressure,
			MidiClockStart,
			MidiClockStop,
			MidiClockFrame,
			MidiClockContinue
		};

		EdoModulatorManager();
		~EdoModulatorManager();

		void restoreMapping (XmlElement *mappingState);
		void addStaticValues (XmlElement *valuesElement);
		void addModulator (XmlElement *modulatorElement);
		void controllerEvent (void *ptr, const int64 newValue);
		void registerController (Component *componentToRegister, const int64 initialValue=0);
		const uint8 getMidiChannel() { return (currentMidiChannel); }
		void setMidiChannel (const uint8 &newMidiChannel);
		void clearCache();
		void processBlock(MidiBuffer& midiMessages);
		static const MidiMessageType stringToMidiType(const String &typeDescirption);
		const int getModulatorForComponent(Component *componentToMatch);
		EdoModulator *getStaticValue (const String &name);
		void addMessageToQueue (const uint8 *dataToAdd, const int dataSize);

		juce_DeclareSingleton (EdoModulatorManager, false)
		juce_UseDebuggingNewOperator

	private:
		OwnedArray <EdoModulator> cache;
		OwnedArray <EdoModulator> staticValues;
		uint8 currentMidiChannel;
		MidiBuffer midiBuffer;
		XmlElement *currentXmlMap;
		bool midiThru;
};

#endif